if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_InsertUser]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_InsertUser]
GO
CREATE PROC sp_InsertUser
	@Username				nvarchar(40),
	@Password				nvarchar(40),
	@Email					varchar(200),
	@Address				varchar(200),
	@Firstname				nvarchar(50),
	@Lastname				nvarchar(100),
	@Phone					varchar(20),
	@Birthday				varchar(20)

AS
BEGIN
	INSERT INTO Account(
			Username,
			Password,
			AccountType
		)
		VALUES(
			@Username,
			@Password,
			1
		)

	DECLARE @AccountID int
	SELECT @AccountID = ID FROM Account WHERE Username = @Username

	INSERT INTO AccountInformation(
			AccountID,
			FirstName,
			LastName,
			Email,
			Address,
			Phone,
			Birthday
		)
		VALUES(
			@AccountID,
			@Firstname,
			@Lastname,
			@Email,
			@Address,
			@Phone,
			@Birthday
		)	
END
